package com.ww.learn.coroutine

import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking

fun main() = runBlocking {
    try {
        val airportCodes = listOf<String>("LAX", "SF-", "PD-", "SEA")

        val jobs: List<Job> = airportCodes.map { anAirportCode ->
            launch {
                val airport = Airport.getAirportData(anAirportCode)
                println("${airport?.code} delay: ${airport?.delay}")
            }
        }
        jobs.forEach { it.join() }
        jobs.forEach { println("Cancelled: ${it.isCancelled}") }
    } catch (ex: Exception) {
        println("ERROR: ${ex.message}")
    }
}